package com.tanhua.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.Query;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.tanhua.common.mapper.UserInfoMapper;
import com.tanhua.common.pojo.UserInfo;
import com.tanhua.server.service.UserInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;

@Service
@Slf4j
public class UserInfoServiceImpl implements UserInfoService {
    @Autowired
    private UserInfoMapper userInfoMapper;

    /**
     * 根据id查询信息
     * @param id
     * @return
     */
    @Override
    public UserInfo queryUserInfoById(Long id) {
        try {
            QueryWrapper<UserInfo> wrapper=new QueryWrapper<>();
            wrapper.eq("user_id",id);
            UserInfo userInfo = userInfoMapper.selectOne(wrapper);
            return userInfo;
        } catch (Exception e) {
           log.error("佳人信息查询失败,数据库查找",e);
        }
        return null;
    }

    @Override
    public List<UserInfo> queryUserInfoList(QueryWrapper<UserInfo> queryWrapper) {
        return this.userInfoMapper.selectList(queryWrapper);
    }

    /**
     * 根据用户id列表查询用户信息
     *
     * @param userIdList
     * @return
     */
    @Override
    public List<UserInfo> queryUserInfoByUserIdList(Collection<?> userIdList) {
        QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("user_id", userIdList);
        return this.queryUserInfoList(queryWrapper);
    }

    @Override
    public boolean updateUserInfoByUserId(UserInfo userInfo) {
        QueryWrapper<UserInfo> wrapper=new QueryWrapper<>();
        wrapper.eq("user_id",userInfo.getUserId());
        int update = this.userInfoMapper.update(userInfo, wrapper);
        return update>0;
    }
}
